import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/404.dart';
import 'package:flutter_enjoy_plus/pages/house/house_list.dart';
import 'package:flutter_enjoy_plus/pages/house/location_list.dart';
import 'package:flutter_enjoy_plus/pages/login/index.dart';
import 'package:flutter_enjoy_plus/pages/notice/index.dart';
import 'package:flutter_enjoy_plus/pages/profile/index.dart';
import 'package:flutter_enjoy_plus/pages/tabs_page.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      "/": (context) => const TabsPage(),
      '/notice_detail':(context)=>const NoticeDetail(),
      '/login':(context)=>const LoginPage(),
      // '/profile':(context)=>const ProfilePage(),
    },
    initialRoute: "/", // 默认路由 第一个页面访问哪一个 ability中 loadContent()
    onGenerateRoute: (setting) {
      final token = tokenmanager.getToken();
      if(token.isEmpty){
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }else{
        if(setting.name == '/profile'){
          return MaterialPageRoute(
            builder: (context) => ProfilePage(
            userInfo: setting.arguments as Map<String, dynamic>,
          ));
        }
        else if(setting.name == '/HouseList'){
          return MaterialPageRoute(
            builder: (context) => const HouseList()
          );
        }
        else if(setting.name == '/add_house'){
          return MaterialPageRoute(
            builder: (context) => const LocationList()
          );
        }
      }
      return MaterialPageRoute(builder: (context) => const NotFoundPage());
      // 需要立刻返回
    },
  ));
}
